package cate.game.play.skill.active;

import cate.common.table.d.GD;
import cate.common.table.d.GDAttr;
import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.buff.BuffParam;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;

import java.util.List;

/**
 * 效果：对敌方后排造成148%魔法伤害，根据伤害总量的150%转化为护盾值平摊给己方生命值最低的3个单位
 * 强化效果：“血之威严”无视护盾，
 */
public class 血之威严AH extends ActiveHandler{

	private double 系数;

	private int 护盾buff;

	private int 目标数;

	private boolean 无视护盾;

	//系数=15000&护盾buff=？？&目标数=3&无视护盾=1
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		系数 = args.getWDouble("系数", 0d);
		护盾buff = args.getInt("护盾buff", 0);
		目标数 = args.getInt("目标数", 0);
		无视护盾 = args.getBoolean("无视护盾", false);
	}

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		if (无视护盾) {
			effect.addIgnShieldRate(GD.W_10000_0);
		}
	}

	@Override
	public void onSkillDone(SkillActionCtx action) {
		double value = action.getStat().getTotalSkillDamage(skill.owner.getPid()) * 系数;
		if (value <= 0) {
			return;
		}
		TargetFilterParam param = new TargetFilterParam().scopeSet(GDSkill.Scope.WE).smallAttrSet(GDAttr.V_HP_LEFT).
				targetNumSet(目标数);
		List<Fighter> targets = TargetSelector.doFind(skill.owner, action.getTeamVs(), param);
		if (XT.isBlank(targets)) {
			return;
		}
		BuffParam buffParam = new BuffParam().buffHpSet(value / targets.size());
		for (Fighter target : targets) {
			target.buff.tryAddByTid(action, skill.owner, 护盾buff, buffParam);
		}
	}
}
